package org.wizard.andy;

import android.app.Activity;
import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ProvaBluetooth extends Activity implements OnClickListener {
	
	private final int REQUEST_ENABLE_BT = 0;
	
    public static final String DEVICE_NAME = "device_name";

	public void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.bluetooth);
		
		Button btn = (Button)findViewById(R.id.btn_bluet);
		btn.setOnClickListener(this);
	}
	

	public void onClick(View v) {
		
		Log.d("ProvaBluetooth", "Button Click");
		BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
		if (bluetoothAdapter == null) {
			AlertDialog.Builder builder = new AlertDialog.Builder(this);
			builder.setTitle("Messaggio di prova");
			builder.setMessage("Bluetooth non supportato");
			builder.create().show();
		}
		else {
			if (!bluetoothAdapter.isEnabled()) {
				Intent activateBluetoothIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
				startActivityForResult(activateBluetoothIntent, REQUEST_ENABLE_BT);
			}
			else {
				Intent gameBoard = new Intent(this, GameBoard.class);
				startActivity(gameBoard);
			}
		}
		
	}
	
	protected void onActivityResult(int requestCode, int resultCode, Intent Data) {
	
		Log.d("Prova Bluetooth", "onActivityResult");
		if (requestCode == REQUEST_ENABLE_BT) {
			if (resultCode == Activity.RESULT_OK) {
				//attivazione bluetooth completata
				//Devo iniziare a cercare i device e far scegliere all'utente..
				
				Intent gameBoard = new Intent(this, GameBoard.class);
				startActivity(gameBoard);
			}
		}
	}
}
